import request from '@/router/axios';
const urlPrefix = '/admin';

export function list(data) {
    return request.post(urlPrefix + '/order/list', data).then(data => {
        data = data || {};
        data.dataList && data.dataList.forEach(el => {
            el.discountType = el.discountType || 0;
            el.payChannel = el.payChannel || 0;
            // el.itemList = el.itemList.concat(el.itemList);
        });
        return data;
    });
}

export function sendGoods({ orderNo, expressNo, expressCompany, expressCompanyCode }) {
    return request.post(urlPrefix + '/order/send_goods', { orderNo, expressNo, expressCompany, expressCompanyCode });
}


export function aggreeRefund(params) {
    return request.post(urlPrefix + '/order/item/refund_apply/process', params);
}

export function sureRefund(params) {
    return request.post(urlPrefix + '/order/item/refund_apply/sure_refund', params);
}

export function receiveRefundGoods(params) {
    return request.post(urlPrefix + '/order/item/refund_apply/confirm_receive', params);
}

export function listRefund(params) {
    return request.post(urlPrefix + '/order/item/list_refund', params).then(data => {
        data = data || {};
        data.dataList && data.dataList.forEach(el => {
            el.itemRefundVo && Object.keys(el.itemRefundVo).forEach(k => {
                if (k == 'id') {
                    return;
                }
                let v = el.itemRefundVo[k];
                if (k == 'applyAccessory' && v) {
                    v = v.split(',');
                } else {
                    v = [];
                }
                el[k] = v;
            });
        });
        return data;
    });
}


export function dataCount() {
    return request.post('/admin/home/count_order');
}
export function VideoView() {
    return request.post('/admin/home/count_video_view');
}
export function dataAmount() {
    return request.post('/admin/home/count_amount');
}

export function exportWaitShip(params) {
    return request.post('/admin/order/export_wait_ship', params);
}
export function exportPlatform(params) {
    return request.post('/admin/order/export_platform', params);
}
export function exportAnchor(params) {
    return request.post('/admin/order/export_anchor', params);
}
